package cn.rkylin.oms.aftersale.sysrefund.utils.dowloadsysrefund.impl;

import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.rkylin.apollo.common.util.HttpUtils;
import cn.rkylin.oms.aftersale.sysrefund.utils.dowloadsysrefund.SysRefundDownloader;

@Service("defaultSysRefundDownloader")
public class DefaultSysRefundDownloaderImpl implements SysRefundDownloader {
    /**
     * jobAddress:自动任务访问地址.
     */
    @Value("${job.address}")
    private String jobAddress;

	@Override
	public JSONObject doDownloadSysRefund(Map requestParam) throws Exception {
		String url = jobAddress + "sysRefundManager/manualGenerateSysRefund.action";

        Iterator<String> iterator = requestParam.keySet().iterator();
        String tempString = "";
        String key = "";
        while (iterator.hasNext()) {
            key = iterator.next();
            tempString = tempString + key + "=" + URLEncoder.encode(requestParam.get(key).toString(),"UTF-8") + "&";
        }
        tempString = tempString.substring(0, tempString.length() - 1);
        
        String resJson = HttpUtils.sendByGet(url, tempString);
        return JSON.parseObject(resJson);
	}

}
